package com.pricl.frame.common.web.rest;

import java.io.Serializable;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;

/**
 * <ol>
 * <li>封装rest api 响应</li>
 * <ol>
 * 
 * @author jackzhong
 * @since 2014年10月24日下午11:43:30
 */
@SuppressWarnings("serial")
public class RestResponse implements Serializable {

	/**
	 * 响应code
	 */
	@JsonProperty("code")
	private String responseCode;

	/**
	 * 响应的数据集
	 */
	@JsonProperty("data")
	private Object responseData;

	/**
	 * 响应的消息
	 */
	@JsonProperty("msg")
	private String responseMsg = "";

	/**
	 * @return the responseCode
	 */
	public String getResponseCode() {
		return responseCode;
	}

	/**
	 * @param responseCode
	 * @param responseMsg
	 */
	public RestResponse(String responseCode, String responseMsg) {
		super();
		this.responseCode = responseCode;
		this.responseMsg = responseMsg;
	}

	/**
	 * @param responseCode
	 * @param responseData
	 */
	public RestResponse(String responseCode, List<?> responseData) {
		super();
		this.responseCode = responseCode;
		this.responseData = responseData;
	}

	/**
	 * @param responseCode
	 * @param responseData
	 * @param responseMsg
	 */
	public RestResponse(String responseCode, List<?> responseData, String responseMsg) {
		super();
		this.responseCode = responseCode;
		this.responseData = responseData;
		this.responseMsg = responseMsg;
	}

	/**
	 * @param responseCode
	 *            the responseCode to set
	 */
	public void setResponseCode(String responseCode) {
		this.responseCode = responseCode;
	}

	/**
	 * @return the responseData
	 */
	public Object getResponseData() {
		return responseData;
	}

	/**
	 * @param responseData
	 *            the responseData to set
	 */
	public void setResponseData(Object responseData) {
		if(responseData == null){
			responseData = Maps.newHashMap();
		}
		this.responseData = responseData;
	}

	/**
	 * @return the responseMsg
	 */
	public String getResponseMsg() {
		return responseMsg;
	}

	/**
	 * @param responseMsg
	 *            the responseMsg to set
	 */
	public void setResponseMsg(String responseMsg) {
		this.responseMsg = responseMsg;
	}
	
	@JsonIgnore
	public boolean isSuccess(){
		return RestResponseCode.getSuccessResponseCode().equals(responseCode);
	}
}
